package com.zlz.open.ugs.starter;

import com.zlz.open.ugs.exchange.UgsExchangeWrapper;
import com.zlz.open.ugs.core.module.Module;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

import java.util.List;

@Slf4j
@Component
public class FilterEntrance implements WebFilter {

    private final List<Module> modules;

    public FilterEntrance(List<Module> modules) {
        this.modules = modules;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        // 包装新的exchange并执行
        UgsExchangeWrapper exchangeWrapper = new UgsExchangeWrapper(exchange, modules);
        return exchangeWrapper.wrapper().start();
    }

}

